package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class RecreateDatabase {
	private static String databaseName = "Carletti";
	private static String username = "kesko";
	private static String password = "Kesko1581";

	public static void main(String[] args) {
		System.out.println(recreate());
	}
	
	public static String create(){
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3307/";			
			Connection connection =	DriverManager.getConnection(url, username, password);
			Statement stmt = connection.createStatement();
			stmt.executeUpdate("create database " + databaseName);
			DaoJPA.getDAO();

			return ("Database created!");
		} catch (Exception e) {
			return ("fejl:  " + e.getMessage());
		}
		
	}
	public static String recreate(){
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3307/" + databaseName ;			
			Connection connection =	DriverManager.getConnection(url, username, password);
			Statement stmt = connection.createStatement();
			stmt.executeUpdate("drop database " + databaseName);
			stmt.executeUpdate("create database " + databaseName);
			DaoJPA.getDAO();
			
			return ("Database recreated!");
		} catch (Exception e) {
			return ("fejl:  " + e.getMessage());
		}
	}
}

